import {defineStore} from 'pinia'
import {
  addOptionsStatus,
  addStringArrStatus,
  removeOptionsArrStatus,
  setCurrentStatus,
  setPicImageStatus,
  setTextPropsStatus
} from '@/store/actions.ts'
import type { EditorComps } from '@/types'

export const useEditor = defineStore('editor', {
  state: () => ({
    currentComponentIndex: -1, // 当前选中的组件索引，一开始都没有选中，所以是-1
    surveyCount: 0, // 问卷题目的数量
    editorComps: [] as EditorComps[], // 问卷题目的数组
  }),
  actions: {
    setTextPropsStatus,
    addStringArrStatus,
    removeOptionsArrStatus,
    setCurrentStatus,
    setPicImageStatus,
    addOptionsStatus,
    addComponent(com: EditorComps) {
      this.editorComps.push(com);
      console.log(this.editorComps)
      this.currentComponentIndex = -1;
      this.surveyCount++;
      // if (isSurveyComName(newCom.name)) this.surveyCount++;
    },
    setCurrentComponentIndex (index: number){
      this.currentComponentIndex = index;
    },
    deleteComponent(index: number){
      this.editorComps.splice(index,1)
    }
  }
}
);
